# 工具箱
from tkinter.tix import Tree
from flask_sqlalchemy import SQLAlchemy
from config import REDIS_DB_URL
from flask_mail import Mail
import redis

# app需要的包
import config
from flask import Flask
from flask_migrate import Migrate
from flask_cors import CORS


def create_app():
    # app对象
    app = Flask(__name__)
    # 导入配置
    app.config.from_object(config)
    # 允许跨域
    CORS(app, resources=r'/*')
    # db对象
    db.init_app(app)
    # 绑定邮箱
    mail.init_app(app)
    # migrate用于操作数据库迁移
    migrate = Migrate(app, db)
    return app, migrate


# 实例化一个db
db = SQLAlchemy()

# 实例化应该redis
redis_sever = redis.Redis(**REDIS_DB_URL)

# 实例化一个邮箱服务
mail = Mail()
